<script setup lang="ts">
import { ElMessage } from "element-plus";
import { removeToken, removeUser } from '../../../utils/session'
import { useRouter } from 'vue-router'
import config from '../../../config'
import { ref } from "vue"
import { useUserStore } from '../../../store/userStore'
import { useTokenStore } from '../../../store/tokenStore'
import { useCrumbStore } from '../../../store/crumbStore'
// import { storeToRefs } from 'pinia'
// import { RoleEnum } from "../../../enums/Role";
import { Operation } from '@element-plus/icons-vue'

defineProps({
  currentTime: String
})
const emits = defineEmits(['handleCollapse'])
const crumbStore = useCrumbStore()
const userStore = useUserStore()
const tokenStore = useTokenStore()
// const { user } = storeToRefs(userStore)
const router = useRouter()
const adminTitle = ref(config.adminTitle)
// const roleTitle = ref('')
const logout = async () => {
  tokenStore.delToken()
  userStore.delUser()
  removeToken()
  removeUser()
  crumbStore.clearCrumb()
  ElMessage({
    type: 'success',
    message: '注销成功'
  })
  await router.push({path: '/login'})
}

const collapseChange = () => {
  emits('handleCollapse')
}
</script>

<template>
  <div class="container">
    <div class="headerLeft">
      <el-icon :size="20" style="cursor: pointer;margin-left: 10px" @click="collapseChange">
        <Operation />
      </el-icon>
      <h2 class="title">{{adminTitle}}</h2>
    </div>
    <div class="userInfo">
      <span class="currentTime">{{ currentTime }}</span>
      <el-popover
          placement="bottom"
          :width="100"
          trigger="click"
      >
        <template #reference>
          <span>欢迎你, 管理员</span>
        </template>
        <div class="opBox" style="cursor: pointer" @click="logout">
          <span>注销</span>
        </div>
      </el-popover>
    </div>
  </div>
</template>

<style lang="less" scoped>
.container {
  width: 100%;
  height: 100%;
  border-bottom: 1px solid #e0e0e0;
  background-color: #fff;
  justify-content: space-between;
  display: flex;
  align-items: center;
  .headerLeft {
    display: flex;
    align-items: center;
    .title {
      font-size: 17px;
      margin-left: 30px;
      color: @GlobalColor;
    }
  }
  .userInfo {
    margin-right: 20px;
    color: @GlobalColor;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    .currentTime {
      margin-right: 40px;
    }
  }
}
</style>
